package org.lizar.util.https;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;

public class Https {

	public static String GetMethod(String url) throws HttpException, IOException{
		HttpClient httpclient = new HttpClient();
		GetMethod httpget = new GetMethod(url);
		String result=null;
		  try { 
		    httpclient.executeMethod(httpget);
		    result=new String(httpget.getResponseBody(),"utf-8");
		  }finally {
		    httpget.releaseConnection();
		  }
		  return result;
	}
	
	public static String PostMethod(String url,String body) throws HttpException, IOException{
		HttpClient httpclient = new HttpClient();
		PostMethod httpPost = new PostMethod(url);
		ByteArrayInputStream is = new ByteArrayInputStream(body.getBytes());
		httpPost.setRequestBody(is);
		String result=null;
		  try { 
		    httpclient.executeMethod(httpPost);
		    result=new String(httpPost.getResponseBody(),"utf-8");
		  }finally {
			  httpPost.releaseConnection();
		  }
		  return result;
	}
	
}
